package org.jeecg.modules.demo.znnqjc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.demo.znnqjc.entity.ZwglZhgj;
import org.jeecg.modules.demo.znnqjc.entity.ZwglZhgjfb;
import org.jeecg.modules.demo.znnqjc.mapper.ZwglZhgjMapper;
import org.jeecg.modules.demo.znnqjc.mapper.ZwglZhgjfbMapper;
import org.jeecg.modules.demo.znnqjc.service.IZwglZhgjfbService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 种植格局附表
 * @Author: jeecg-boot
 * @Date:   2023-04-21
 * @Version: V1.0
 */
@Service
public class ZwglZhgjfbServiceImpl extends ServiceImpl<ZwglZhgjfbMapper, ZwglZhgjfb> implements IZwglZhgjfbService {
	
	@Autowired
	private ZwglZhgjfbMapper zwglZhgjfbMapper;
	@Autowired
	private ZwglZhgjMapper z;
	
	@Override
	public List<ZwglZhgjfb> selectByMainId(String mainId) {
		return zwglZhgjfbMapper.selectByMainId(mainId);
	}


	@Override
	public List<Map<String, Object>> getsum(){
		List<Map<String, Object>> aggregatedResults = new ArrayList<>();
		QueryWrapper<ZwglZhgj> queryWrapper = new QueryWrapper<>();
		List<ZwglZhgj> mainTableEntities = z.selectList(queryWrapper);
		ZwglZhgj zwglZhgj = new ZwglZhgj();
		List<Map<String, Object>> results = zwglZhgjfbMapper.selectTotalSumGroupedByDj();
			System.out.println(results);
		for (Map<String, Object> result : results) {
			zwglZhgj.setYm(String.valueOf(result.get("sum_ym")));
			zwglZhgj.setDd(String.valueOf(result.get("sum_dd")));
			zwglZhgj.setSd(String.valueOf(result.get("sum_sd")));
			zwglZhgj.setQt(String.valueOf(result.get("sum_qt")));
			zwglZhgj.setId(String.valueOf(result.get("wj")));
			z.updateById(zwglZhgj);
		}

		return aggregatedResults;
	}
}
